home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0385.arc
/
DEBUG2.H
< prev
next >
Wrap
Text File
|
1986-02-27
|
5KB
|
192 lines
/* debug2.h -- Control debugging code generation and execution. */
/* by Alexander B. Abacus */
/* This a more portable version of debug.h, debug.h is more readable */
/*[ A.0 ] Xfeature defined if feature is absent from environment */
#ifndef Xvoid
#ifdef MSDOS
#define Xvoid
#endif MSDOS
#endif Xvoid
/*[ A.1 ] Prevent redefinitions. */
#ifndef FILE
#ifdef Debug
#include <stdio.h>
#endif defined Debug
#endif ? defined FILE
/*[ A.2 ] Localize differences between definitions and declarations. */
#ifdef Hdebug
#undef Extern
#undef Init
#endif Hdebug
#ifndef DebugAll
#define DebugAll 0
#endif ! defined DebugAll
#ifndef Storage
#define Extern extern
#define Init(A_Value)
#else defined Storage ("static" or "")
#define Extern Storage
#define Init(A_Value) = A_Value
#endif ? defined Storage
Extern char debug[128] Init( { DebugAll } );
#ifndef Hdebug
/* else skip to end of file */
#define Hdebug
#define _ ,
/* last definition is necessary for Init( { 1 _ 2 _ 3 } ) */
/*[ A.3 ] Localize dependancies on debugging options. */
#ifdef Xvoid
#define void int
#endif Xvoid
#ifndef Debug
#define DEBUGIN(A_Text)
#define DEBUGOUT(A_Text) A_Text
#define Nothing
#define Void void
#else defined Debug
#define DEBUGIN(A_Text) A_Text
#define DEBUGOUT(A_Text)
#define Nothing 0
#define Void int
#endif ? defined Debug
/*[ A.4 ] Procedure tracing -- entering. */
/* EndAutoStorage is only used from START() but is taken out of it because */
/* START() was getting too big for some preprocessors. */
#ifndef Debug
#define EndAutoStorage
#else defined Debug
#define EndAutoStorage \
struct { char procId, *procName, *procForm; } thisProc; \
struct { char blockLevel; } thisBlock;
#endif Debug
#ifdef Debug
#define START(A_ProcId, A_ProcName, A_ProcForm) EndAutoStorage \
thisProc.procName = A_ProcName; thisProc.procId = ((A_ProcId) % 128); \
thisProc.procForm = A_ProcForm; thisBlock.blockLevel = 1; \
if ( debug[0] || (debug[thisProc.procId % 128] >= 1) ) \
{ StdMsg ( stderr , "Procedure entered.\n" ); }
#else
#define START(A_ProcId, A_ProcName, A_ProcForm)
#endif Debug
/*[ A.5 ] Annotate error messages. */
#ifdef __LINE__
#define StdMsg (void) fprintf \
( stderr, DEBUGIN("%14s|%4d|%16|%c%d|") DEBUGOUT("%14s|%4d|") , __FILE__, __LINE__ \
DEBUGIN( _ thisProc.procName _ thisProc.procId _ thisBlock.blockLevel ) \
); (void) fprintf
#else ! defined __LINE__
#define StdMsg (void) fprintf \
( stderr, DEBUGIN("%16s|%c%d|") DEBUGOUT("") \
DEBUGIN( _ thisProc.procName _ thisProc.procId _ thisBlock.blockLevel ) \
); (void) fprintf
#endif ? defined __LINE__
/*[ A.6 ] Selective debugging. */
#ifndef Debug
#define DEBUG(A_Level, A_Text)
#else defined Debug
#define DEBUG(A_Level, A_Text) \
if ( debug[0] || (debug[thisProc.procId % 128] >= (A_Level)) ) \
{ struct { char blockLevel; } thisBlock; thisBlock.blockLevel = (A_Level); A_Text }
#endif ? defined Debug
#define BeginDEBUG(A_Level) \
if ( debug[0] || (debug[thisProc.procId % 128] >= (A_Level)) ) \
{ struct { char blockLevel; } thisBlock; thisBlock.blockLevel = (A_Level);
#define EndDEBUG }
/*[ A.7 ] Procedure tracing -- termination. */
#ifndef Debug
#define RETURN(A_Value) return A_Value ;
#else defined Debug
#define RETURN(A_Value) if ( debug[0] || (debug[thisProc.procId % 128] >= 1) ) \
{ StdMsg ( stderr , "Procedure returned" ); if ( thisProc.procForm != 0 ) \
{ fprintf ( stderr, thisProc.procForm , A_Value); } fprintf ( stderr, ".\n"); \
} return A_Value ;
#endif ? defined Debug
#ifndef Debug
#define EXIT(A_Value) (void) exit((int) (A_Value));
#else defined Debug
#define EXIT(A_Value) if ( debug[0] || (debug[thisProc.procId] >= 1) ) \
{ StdMsg ( stderr , "Program terminated normally.\n" ); } \
(void) exit((int)(A_Value));
#endif ? defined Debug
#ifndef Debug
#define ABEND(A_Value) (void) exit((int) (A_Value));
#else defined Debug
#define ABEND(A_Value) {StdMsg(stderr, "Program terminated abnormally.\n");} \
(void) exit((int) (A_Value));
#endif ? defined Debug
/*[ A.8 ] Assert. */
#ifndef Debug
#define ASSERT(A_Predicate)
#else defined Debug
#define ASSERT(A_Predicate) if ( ! (A_Predicate) ) \
{ StdMsg ( stderr, "False assertion: (%s).\n", "A_Predicate" ); ABEND(1); }
#endif ? defined Debug
#ifdef DriverH
#define Storage static
/* To compile it with -DDriverH, this file must be renamed into: */
#include "debug.c"
char * echo( string )
char * string;
{ /* echo() */
START ( 'e', "echo", " \"%s\"" )
RETURN ( string )
} /* echo() */
Void main (argc, argv)
int argc;
char *argv[];
{ /* main() */
int index;
START ( 'm', "main", 0 )
DEBUGIN( debug[0] = 0; debug['m'] = 2; debug['e'] = 1; )
ASSERT (argc > 1)
for ( (index = 1); (index < argc); (++index) )
{
StdMsg ( stderr, "Argument %d is \"%s\".\n", index, argv[index] );
DEBUG ( 2, StdMsg ( stderr, "Argument %d is \"%s\".\n", index, argv[index] ); )
(void) echo ( argv[index] );
}
EXIT ( 0 );
} /* main */
#endif ! defined DriverH
#endif ! defined Hdebug
/* debug.h -- End of file */